package com.dream.keigezhushou.Activity.acty.personal;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.dream.keigezhushou.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyKgeActivity extends AppCompatActivity {

    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.kge_list)
    ListView kgeList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_kge);
        ButterKnife.bind(this);
        initView();
        initData();
    }

    //初始化界面
    protected void initView(){

        tvTitle.setText("我的K歌");

    }

    //初始化数据
    protected void initData(){

        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //返回
                finish();
            }
        });


        //ListView创建适配器
        kgeList.setAdapter(new KgeAdapter());
    }


    public class KgeAdapter extends BaseAdapter {

        int c = 20;

        public KgeAdapter() {
            super();
        }

        @Override
        public int getCount() {
            return c;
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder mHolder = null;

            if (convertView == null){

                convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.layout_k_item,null);
                mHolder = new ViewHolder();
                convertView.setTag(mHolder);
            }else {
                mHolder = (ViewHolder)convertView.getTag();
            }

            mHolder.mImageView = (ImageView) convertView.findViewById(R.id.iv_zan);
            mHolder.tvZanNum = (TextView)convertView.findViewById(R.id.tv_zan_num);
            //mHolder.tvZanNum.setText("i");

            final ViewHolder finalMHolder = mHolder;
            mHolder.mImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //点击之后状态发生改变，且按钮不能再被点击
                    finalMHolder.mImageView.setSelected(true);
                    finalMHolder.mImageView.setClickable(false);
                    //点赞人数发生变化
                    //finalMHolder.tvZanNum.setText(i+);
                }
            });
            return convertView;
        }

        class ViewHolder{

            ImageView mImageView;
            TextView tvSong,tvSinger,tvDate,tvZanNum,tvEvaluateNum;
        }
    }
}
